//
//  DDTMainTabbarController.swift
//  weibo
//
//  Created by mac on 16/9/20.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class DDTMainTabbarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let DDTTabBar = DDTMainTabBar()
        DDTTabBar.composeClosure = { () -> Void in
            /**
            中间按钮点击事件
            */
            print("composeClick")
            
        }

       setValue(DDTTabBar, forKey: "tabBar")
        //添加子tabbar
        addAppChildViewControllers()
        
    }

  //添加子tabbar
    private func addAppChildViewControllers() {
    
        //首页
        addTabbar(DDTHomeViewController(), title: "首页", ImageString: "tabbar_home")
        //消息
        addTabbar(DDTMessageViewController(), title: "消息", ImageString: "tabbar_message_center")
        //发现
        addTabbar(DDTDiscoverViewController(), title: "发现", ImageString: "tabbar_discover")
        //我
        addTabbar(DDTProfileViewController(), title: "我", ImageString: "tabbar_profile")
        
        
    }
    
    //封装tabbar子控制器方法
    private func addTabbar(Vc:UIViewController,title:String,ImageString:String) {
        Vc.title = title
        Vc.tabBarItem.image = UIImage(named: ImageString)
        let selecteIamgeName = ImageString + "_selected";
        //渲染图片
        Vc.tabBarItem.selectedImage = UIImage(named: selecteIamgeName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //文字 颜色
        Vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        self.addChildViewController(UINavigationController(rootViewController: Vc))
        
    }
    
    

}
